package com.trade.tradebusiness.trade.order;

import com.trade.core.exception.TradeBaseException;
import com.trade.core.message.TradeObjectRestResponse;
import com.trade.core.trade.TradeProcessorStepAbstract;
import com.trade.tradebusiness.entity.dto.TradeCreateOrderCheckDataDTO;
import com.trade.tradebusiness.entity.vo.TradeCreateOrderCheckDataVO;
import com.trade.tradebusiness.enums.OrderTradeProcessorStepEnums;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;


/**
 * @author sven.wang
 * @version 2022/1/6 15:26
 * @Description: 下单校验数据
 */
@Service
@Slf4j
public class CreateOrderCheckDataTradeStep extends TradeProcessorStepAbstract<TradeCreateOrderCheckDataDTO,TradeCreateOrderCheckDataVO> {

    @Override
    public String step() {
        return OrderTradeProcessorStepEnums.ORDER_CHECK_DATA.name();
    }

    @Override
    public void checkParam(TradeCreateOrderCheckDataDTO param) {
        //相关参数检查
        if (StringUtils.isBlank(param.getProductId())) {
            throw new TradeBaseException("产品id不能为空！");
        }
        if (param.getOrderAmt() == null) {
            throw new TradeBaseException("订单金额不能为空！");
        }
    }

    @Override
    public TradeObjectRestResponse<TradeCreateOrderCheckDataVO> doProcess(TradeCreateOrderCheckDataDTO param) {

        TradeCreateOrderCheckDataVO vo = new TradeCreateOrderCheckDataVO();
        vo.setUserPhone("13974747474");
        vo.setUserId(param.getUserId());
        return TradeObjectRestResponse.success(vo);
    }

    @Override
    public void checkOutParam(TradeCreateOrderCheckDataVO outParam) {
        if(StringUtils.isBlank(outParam.getUserId())){
            throw new TradeBaseException("步骤返回数据异常: 用户id不存在");
        }
        if(StringUtils.isBlank(outParam.getUserPhone())){
            throw new TradeBaseException("步骤返回数据异常: 用户手机号不存在");
        }
    }
}
